package com.cheer.dao;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cheer.entity.ExPresentAudioVoteEntity;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * 用户信息
 *
 * @author cheer
 */
@Mapper
@Repository
public interface ExPresentAudioVoteDao extends BaseMapper<ExPresentAudioVoteEntity> {

    default List<ExPresentAudioVoteEntity> selectByUserIdAndAudioId(Integer userId, List<Integer> audioIds) {
        return selectList(new QueryWrapper<ExPresentAudioVoteEntity>()
                .eq("user_id", userId).in("audio_id", audioIds));
    }

    default List<ExPresentAudioVoteEntity> selectByUserIdAndAudioId(Integer userId, Integer audioId) {
        Date today = DateUtil.beginOfDay(new Date());
        return selectList(new QueryWrapper<ExPresentAudioVoteEntity>()
                .eq("user_id", userId).eq("audio_id", audioId).ge("create_time", today));
    }

    default List<ExPresentAudioVoteEntity> selectByUserId(Integer userId) {
        Date today = DateUtil.beginOfDay(new Date());
        return selectList(new QueryWrapper<ExPresentAudioVoteEntity>()
                .eq("user_id", userId).ge("create_time", today));
    }


}
